<?php
class GroupTable extends Doctrine_Table
{
    public function createSelect($required = true, $multiple = false)
    {
        $pairs = $this->fetchPairs('id', 'name');
        $select = new Zend_Form_Element_Select('group_id', array('multiple' => $multiple));
        $select
            ->setRequired($required)
            ->addMultioption('0', '---Select group---')
            ->addMultiOptions($pairs)
            ->setLabel('Group');
        return $select;
    }

    public function fetchPairs($key = 'id', $name = 'name')
    {
        $query = $this->createQuery()
            ->select($key.', '.$name)
            ->orderBy($name)
            ->setHydrationMode(Doctrine::HYDRATE_ARRAY);

        $rows = $query->execute();
        $pairs = array();

        foreach ($rows as $row)
        {
            $pairs[$row[$key]] = $row[$name];
        }
        return $pairs;
    }
}
?>